package com.alphathink.deliveryassist;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.AlphaThink.DeliveryAssist.R;
import com.alphathink.deliveryassist.commonutils.L;
import com.alphathink.deliveryassist.util.SharePrefUtil;
import com.alphathink.deliveryassist.util.UpdateVersionUtil;

/***
 * 开始界面
 * 
 * @author click
 * 
 */
public class WelcomeActivity extends Activity {
	private int localVersion;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_welcome);

		SharedPreferences preferences = SharePrefUtil
				.getPref(getApplicationContext());
		String state = preferences.getString(SharePrefUtil.STATE, "");
		String selectModel = preferences.getString(SharePrefUtil.SELECTMODEL,
				"");

		SharedPreferences.Editor editor = preferences.edit();
		localVersion = UpdateVersionUtil.getLocalVersion(
				getApplicationContext(), localVersion);
		Log.e("WelcomeActivity", "当前版本:" + localVersion);
		editor.putString(SharePrefUtil.LOCAL_VERSION,
				String.valueOf(localVersion));
		editor.commit();
		Log.d("本地版本欢迎界面",
				preferences.getString(SharePrefUtil.LOCAL_VERSION, ""));
		Intent intent = new Intent();
		if ("".equals(state) || "false".equals(state)) {
			intent.setClass(WelcomeActivity.this, GuideActivity.class);
			startActivity(intent);
			WelcomeActivity.this.finish();
		} else if ("true".equals(state) && "".equals(selectModel)) {
			intent.setClass(WelcomeActivity.this, ModelSelectActivity.class);
			startActivity(intent);
			Log.d("状态",
					"state-------"
							+ preferences.getString(SharePrefUtil.STATE, ""));
			Log.d("主页", "---------->Main");
			WelcomeActivity.this.finish();

		} else if ("true".equals(state) && "0".equals(selectModel)) {
			intent.setClass(WelcomeActivity.this, MainActivity.class);
			startActivity(intent);
			WelcomeActivity.this.finish();
		} else if ("true".equals(state) && "1".equals(selectModel)) {
			intent.setClass(WelcomeActivity.this, MainActivity.class);
			startActivity(intent);

			WelcomeActivity.this.finish();
		}

	}

}
